<?php

namespace App\Entity;

use App\Models\DistributorPoster;

class DistributorPosterEntity extends ABaseEntity
{
    public function __construct(DistributorPoster $model)
    {
        $this->model = $model;
    }

    /**
     * @return int
     */
    public function getId(): int
    {
        return (int)$this->model->id;
    }

    /**
     * @param int $id
     */
    public function setId(int $id): void
    {
        $this->model->id = $id;
    }

    /**
     * @return string
     */
    public function getCreatedAt(): string
    {
        return (string)$this->model->created_at;
    }

    /**
     * @param string $created_at
     */
    public function setCreatedAt(string $created_at): void
    {
        $this->model->created_at = $created_at;
    }

    /**
     * @return string
     */
    public function getUpdatedAt(): string
    {
        return (string)$this->model->updated_at;
    }

    /**
     * @param string $updated_at
     */
    public function setUpdatedAt(string $updated_at): void
    {
        $this->model->updated_at = $updated_at;
    }

    /**
     * @return int
     */
    public function getUserId(): int
    {
        return (int)$this->model->user_id;
    }

    /**
     * @param int $user_id
     */
    public function setUserId(int $user_id): void
    {
        $this->model->user_id = $user_id;
    }

    /**
     * @return string
     */
    public function getOpenid(): string
    {
        return (string)$this->model->openid;
    }

    /**
     * @param string $openid
     */
    public function setOpenid(string $openid): void
    {
        $this->model->openid = $openid;
    }

    /**
     * @return string
     */
    public function getUrl(): string
    {
        return (string)$this->model->url;
    }

    /**
     * @param string $url
     */
    public function setUrl(string $url): void
    {
        $this->model->url = $url;
    }

    /**
     * @param int $userId
     * @return bool
     */
    public static function isExisted(int $userId): bool
    {
        return DistributorPoster::query()->where('user_id', $userId)->exists();
    }

    /**
     * @param int $userId
     * @return static|null
     */
    public static function findByUserId(int $userId): ?self
    {
        /** @var DistributorPoster $distributorPoster */
        $distributorPoster = DistributorPoster::query()->where('user_id', $userId)->first();
        if (empty($distributorPoster)) {
            return null;
        }
        return new self($distributorPoster);
    }

    /**
     * @param int $userId
     * @return static|null
     */
    public static function findByUserIdProductId(int $userId, int $productId): ?self
    {
        /** @var DistributorPoster $distributorPoster */
        $distributorPoster = DistributorPoster::query()->where('user_id', $userId)->first();
        if (empty($distributorPoster)) {
            return null;
        }
        return new self($distributorPoster);
    }

    /**
     * @param int $userId
     * @return static|null
     */
    public static function findByUserIdConvertible(int $userId): ?self
    {
        /** @var DistributorPoster $distributorPoster */
        $distributorPoster = DistributorPoster::query()->where('user_id', $userId)->first();
        if (empty($distributorPoster)) {
            return null;
        }
        return new self($distributorPoster);
    }

    /**
     * @return string
     */
    public function getType(): string
    {
        return (string)$this->model->type;
    }

    /**
     * @param string $type
     */
    public function setType(string $type): void
    {
        $this->model->type = $type;
    }

    /**
     * @return int
     */
    public function getProductId(): int
    {
        return (int)$this->model->product_id;
    }

    /**
     * @param int $product_id
     */
    public function setProductId(int $product_id): void
    {
        $this->model->product_id = $product_id;
    }

    /**
     * @return int
     */
    public function getConvertibleCardId(): int
    {
        return (int)$this->model->convertible_card_id;
    }

    /**
     * @param int $convertible_card_id
     */
    public function setConvertibleCardId(int $convertible_card_id): void
    {
        $this->model->convertible_card_id = $convertible_card_id;
    }
}
